﻿
function checkAll(objRef, type, session) {
    debugger;
    if (type == 'H') {
        var GridView = objRef.parentNode.parentNode.parentNode;
        var inputList = GridView.getElementsByTagName("input");
        if (session == "first") {
            for (var i = 0; i < inputList.length; i++) {
                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        inputList[i].checked = true;
                        if (inputList[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                            inputList[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "lightgreen";
                    }
                    else {
                        inputList[i].checked = false;
                        if (inputList[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                            inputList[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "white";
                    }
                }
                if (i == 0) {
                    i++;
                }
                else {
                    i++;
                    i++;
                }
            }
        }
        if (session == "second") {
            for (var i = 0; i < inputList.length; i++) {
                if (i + 3 <= inputList.length) {
                    if (inputList[i + 3].type == "checkbox" && objRef != inputList[i + 3]) {
                        if (objRef.checked) {
                            inputList[i + 3].checked = true;
                            if (inputList[i + 3].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                                inputList[i + 3].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "lightgreen";
                        }
                        else {
                            inputList[i + 3].checked = false;
                            if (inputList[i + 3].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                                inputList[i + 3].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "white";
                        }
                    }

                    if (i == 1) {
                        i++;
                    }
                    else {
                        i++;
                        i++;
                    }
                }
            }
        }
    }
    if (type == 'I') {
        var row = objRef.parentNode.parentNode;
        var GridView = row.parentNode;
        var inputList = GridView.getElementsByTagName("input");

        if (objRef.checked == false) {
            var CA;
            if (session == "first") {
                CA = $('#ContentPlaceHolder1_gvAssessorCalendar_checkAllFirstHalf');
            }
            if (session == "second") {
                CA = $('#ContentPlaceHolder1_gvAssessorCalendar_checkAllSecondHalf');
            }
            CA[0].checked = false;
            if (objRef.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                objRef.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "white";
        }
        else {
            if (objRef.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor != "rgb(255, 102, 0)")
                objRef.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "lightgreen";
        }
    }
}